package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAccountTraceMapper;
import com.qf.pojo.DtsAccountTrace;
import com.qf.pojo.DtsUser;
import com.qf.service.DtsAccountTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DtsAccountTraceServiceImpl implements DtsAccountTraceService {
    @Autowired
    DtsAccountTraceMapper dtsAccountTraceMapper;
    @Override
    public Map<String, Object> queryPage(Integer page, Integer limit, String username, String mobile, Integer statusArray, String sort, String order) {
        IPage<DtsAccountTrace> iPage = new Page<>(page, limit);

        QueryWrapper<DtsAccountTrace> wrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(username)){
            wrapper.like("user_id",username);
        }
        if (!StringUtils.isEmpty(mobile)) {
            wrapper.eq("mobile", mobile);
        }
        if (!StringUtils.isEmpty(statusArray)) {
            wrapper.eq("status", statusArray);
        }
        if ("desc".equals(order)){
            wrapper.orderByDesc(sort);
        }else {
            wrapper.orderByAsc(sort);
        }
        dtsAccountTraceMapper.selectPage(iPage,wrapper);
        long total = iPage.getTotal();
        List<DtsAccountTrace> records = iPage.getRecords();
        Map<String, Object> data = new HashMap<>();
        data.put("total",total);
        data.put("traceList",records);
        return data;
    }
    @Override
    public void update(DtsAccountTrace account) {
        dtsAccountTraceMapper.updateById(account);
    }
}